local fa = fk.CreateSkill {
    name = "ym1__fa",
}
fa:addEffect(fk.CardUseFinished,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(fa.name) then
            local room = player.room
            local choices = table.map(player:getTableMark("@ym1__fa"), function (choice)
                return "#"..string.sub(choice, 2)
            end)
            if #choices == 4 then
                table.removeOne(choices,"#ym1__fa4")
            end
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets == 0 then table.removeOne(choices,"#ym1__fa3") end
            table.removeOne(choices,"#ym1__fa1")
            return target == player and data.card.trueName == "slash" and not(data.extra_data and data.extra_data.ym1__fa) and #choices > 0
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices, all_choices = table.map(player:getTableMark("@ym1__fa"), function (choice)
            return "#"..string.sub(choice, 2)
        end),table.map(player:getTableMark("@ym1__fa"), function (choice)
            return "#"..string.sub(choice, 2)
        end)
        table.removeOne(choices,"#ym1__fa1")
        if table.contains(choices,"#ym1__fa3") then
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets == 0 then table.removeOne(choices,"#ym1__fa3") end
        end
        if #choices > 0 then
            table.insert(choices,"Cancel")
            table.insert(all_choices,"Cancel")
            local result = room:askToChoice(player,{
                choices = choices,
                skill_name = fa.name,
                prompt = "#ym1__fa-prompt",
                all_choices = all_choices,
            })
            if result ~= "Cancel" then
                self.cost_data = result
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local marks = player:getTableMark("@ym1__fa")
        table.removeOne(marks,"@"..string.sub(self.cost_data, 2))
        room:setPlayerMark(player, "@ym1__fa",marks)
        if self.cost_data == "#ym1__fa1" then
            local use = room:askToUseCard(player, {
                pattern = "slash",
                skill_name = fa.name,
                prompt = "#ym1__tian-slash",
                cancelable = true,
            })
            if use then
                use.extraUse = true
                use.extra_data = use.extra_data or {}
                use.extra_data.ym1__fa = true
                room:useCard(use)
            end
        elseif self.cost_data == "#ym1__fa2" then
            player:drawCards(1, fa.name)
        elseif self.cost_data == "#ym1__fa3" then
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets > 0 then
                local to = room:askToChoosePlayers(player,{
                    skill_name = fa.name,
                    targets = targets,
                    min_num = 1,
                    max_num = 1,
                    prompt = "#ym1__tian-discard",
                    cancelable = false,
                })
                to = room:getPlayerById(to[1].id)
                local card = #to:getCardIds("ej") == 1 and to:getCardIds("ej") or room:askToChooseCard(player,{
                    target = to,
                    flag = "ej",
                    skill_name = fa.name,
                    prompt = "#ym1__tian-discard"
                })
                room:throwCard(card, fa.name, to, player)
            end
        else
            room:setPlayerMark(player, "@ym1__fa", {"@ym1__fa1", "@ym1__fa2", "@ym1__fa3", "@ym1__fa4"})
        end
    end,
})
fa:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            local room = player.room
            local choices = table.map(player:getTableMark("@ym1__fa"), function (choice)
                return "#"..string.sub(choice, 2)
            end)
            if #choices == 4 then
                table.removeOne(choices,"#ym1__fa4")
            end
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets == 0 then table.removeOne(choices,"#ym1__fa3") end
            for _, move in ipairs(data) do
                p(move.moveReason)
                if move.moveReason == fk.ReasonDraw then
                    if move.to == player and move.skillName ~= fa.name and #move.moveInfo == 1 then
                        p(choices)
                        table.removeOne(choices,"#ym1__fa2")
                        if #choices > 0 then return true end
                    end
                elseif move.moveReason == fk.ReasonDiscard then
                    if #move.moveInfo > 0 and move.skillName ~= fa.name and ((move.proposer and  move.proposer == player) or (move.from and move.from == player)) then
                        for _, info in ipairs(move.moveInfo) do
                            if table.contains({Card.PlayerEquip,Card.PlayerJudge},info.fromArea) then
                                if table.contains(choices,"#ym1__fa3") then table.removeOne(choices,"#ym1__fa3") end
                                if #choices > 0 then return true end
                            end
                        end
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices, all_choices = table.map(player:getTableMark("@ym1__fa"), function (choice)
            return "#"..string.sub(choice, 2)
        end),table.map(player:getTableMark("@ym1__fa"), function (choice)
            return "#"..string.sub(choice, 2)
        end)
        for _, move in ipairs(data) do
            if move.moveReason == fk.ReasonDraw then
                table.removeOne(choices,"#ym1__fa2")
                break
            elseif move.moveReason == fk.ReasonDiscard then
                table.removeOne(choices,"#ym1__fa3")
                break
            end
        end
        if table.contains(choices,"#ym1__fa3") then
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets == 0 then table.removeOne(choices,"#ym1__fa3") end
        end
        if #choices > 0 then
            table.insert(choices,"Cancel")
            table.insert(all_choices,"Cancel")
            local result = room:askToChoice(player,{
                choices = choices,
                skill_name = fa.name,
                prompt = "#ym1__tian-prompt",
                all_choices = all_choices,
            })
            if result ~= "Cancel" then
                self.cost_data = result
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local marks = player:getTableMark("@ym1__fa")
        table.removeOne(marks,"@"..string.sub(self.cost_data, 2))
        room:setPlayerMark(player, "@ym1__fa",marks)
        if self.cost_data == "#ym1__fa1" then
            local use = room:askToUseCard(player, {
                pattern = "slash",
                skill_name = fa.name,
                prompt = "#ym1__tian-slash",
                cancelable = true,
            })
            if use then
                use.extraUse = true
                use.extra_data = use.extra_data or {}
                use.extra_data.ym1__fa = true
                room:useCard(use)
            end
        elseif self.cost_data == "#ym1__fa2" then
            player:drawCards(1, fa.name)
        elseif self.cost_data == "#ym1__fa3" then
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            if #targets > 0 then
                local to = room:askToChoosePlayers(player,{
                    skill_name = fa.name,
                    targets = targets,
                    min_num = 1,
                    max_num = 1,
                    prompt = "#ym1__tian-discard",
                    cancelable = false,
                })
                to = room:getPlayerById(to[1].id)
                local card = #to:getCardIds("ej") == 1 and to:getCardIds("ej") or room:askToChooseCard(player,{
                    target = to,
                    flag = "ej",
                    skill_name = fa.name,
                    prompt = "#ym1__tian-discard"
                })
                room:throwCard(card, fa.name, to, player)
            end
        else
            room:setPlayerMark(player, "@ym1__fa", {"@ym1__fa1", "@ym1__fa2", "@ym1__fa3", "@ym1__fa4"})
        end
    end,
})
fa:addEffect(fk.RoundEnd,{
    can_refresh = function (self, event, target, player, data)
        return player:getMark("ym1__zhu") ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local skills = player:getMark("ym1__zhu")
        room:setPlayerMark(player,"ym1__zhu",0)
        room:handleAddLoseSkills(player,table.concat(skills,"|").."|-ym1__fa|-ym1__tian",nil,true)
    end,
})
fa:addEffect("targetmod",{
    residue_func = function(self, player, skill, scope)
        if player:hasSkill(fa.name) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
            return 1
        end
    end,
})
fa:addAcquireEffect(function (self, player, is_start)
    player.room:setPlayerMark(player, "@ym1__fa", {"@ym1__fa1", "@ym1__fa2", "@ym1__fa3", "@ym1__fa4"})
end)
fa:addLoseEffect(function (self, player, is_death)
    player.room:setPlayerMark(player, "@ym1__fa", 0)
end)
Fk:loadTranslationTable{
    ["ym1__fa"] = "罚",
    [":ym1__fa"] = "你使用【杀】的次数上限+1。你不因此技能执行以下一项结束后，可执行未选择过的另一项：1.使用一张【杀】；2.摸一张牌；3.弃置场上一张牌；4.重置此技能。",
    ["@ym1__fa"] = "罚",
    ["@ym1__fa1"] = "Ⅰ",
    ["#ym1__fa1"] = "使用一张【杀】",
    ["@ym1__fa2"] = "Ⅱ",
    ["#ym1__fa2"] = "摸一张牌",
    ["@ym1__fa3"] = "Ⅲ",
    ["#ym1__fa3"] = "弃置场上一张牌",
    ["@ym1__fa4"] = "Ⅳ",
    ["#ym1__fa4"] = "重置此技能",
    ["#ym1__fa-prompt"] = "罚：你可以执行你未选择过的一项",
    ["#ym1__fa-slash"] = "罚：使用一张【杀】",
    ["#ym1__fa-discard"] = "罚：弃置场上一张牌",

    ["$ym1__fa1"] = "一招误判，满盘皆输。",
    ["$ym1__fa2"] = "我会撕碎你手中的胜利。",
    ["$ym1__fa3"] = "既然你只懂暴力，我会让你见识真正的暴力！",
    ["$ym1__fa4"] = "现在看清你的错误了吗？",
    ["$ym1__fa5"] = "和我一起，惩罚他们！",
    ["$ym1__fa6"] = "小小蝼蚁。",
    ["$ym1__fa7"] = "让他们归于大地。",
    ["$ym1__fa8"] = "夺走他们的一切。",
}
return fa